
import NoticeAPI from '../api/notice.js';

export const Notice={
   state:{
      noticelist:[],
      notice_total_count:0,
      editNoticeStatus:-1,     //插入状态 0失败  1成功  -1不改变
      noticeinfo:[],
      delNoticeStatus:-1,       //删除状态
      allnoticetype:[]   //公告发布位置
   },
   mutations:{
      setNoticeList(state,list){
          state.noticelist=list;
      },
      setNoticeTotalCount(state,total_count){
          state.notice_total_count=total_count;
      },
      setEditNoticeStatus(state,status){
          state.editNoticeStatus=status;
      },
      setNoticeInfo(state,info){
          state.noticeinfo=info;
      },
      setDelNoticeStatus(state,status){
          state.delNoticeStatus=status;
      },
      setAllNoticeType(state,list){
          state.allnoticetype=list;
      }
   },
   actions:{
      loadNoticeList(context,data){
          NoticeAPI.getNoticeList(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setNoticeList',response.data.list);
                  context.commit('setNoticeTotalCount',response.data.total_count);
              }
          })
      },
      //插入notice
      editNotice(context,data){
          NoticeAPI.editNotice(data).then(function(response){
              context.commit('setEditNoticeStatus',response.data.code);
          })
      },
      //获取详情
      loadNoticeInfo(context,data){
          NoticeAPI.getNoticeInfo(data).then(function(response){
              if(response.data.code==1){
                  context.commit('setNoticeInfo',response.data.info);
              }
          })
      },
      //删除
      delNotice(context,data){
          NoticeAPI.delNotice(data).then(function(response){
                context.commit('setDelNoticeStatus',response.data.code);
          })
      },
      loadAllNoticeType(context,data){
          NoticeAPI.getAllNoticeType(data).then(function(response){
                context.commit('setAllNoticeType',response.data.list);
          })
      }
   },
   getters:{
      getNoticeList:state =>{
         return state.noticelist
      },
      getNoticeTotalCount: state =>{
         return state.notice_total_count
      },
      getEditNoticeStatus:state=>{
          return state.editNoticeStatus;
      },
      getNoticeInfo:state => {
          return state.noticeinfo;
      },
      getDelNoticeStatus:state => {
          return state.delNoticeStatus;
      },
      getAllNoticeType:state => {
          return state.allnoticetype;
      }
   }
}
